#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

class Solution {
public:
	int reverse(int x) {
		string s = std::to_string(x);
		string inv_s;
		string max_pos = to_string(numeric_limits<int>().max());
		string max_neg = to_string(numeric_limits<int>().min());
		if (s[0] == '-'){
			inv_s.push_back('-');
			for (string::reverse_iterator iter = s.rbegin(); iter != s.rend()-1; iter++){
				inv_s.push_back(*iter);
			}
			if (inv_s.length() > max_neg.length()) inv_s = "0";
			else if (inv_s.length() == max_neg.length()){
				if (inv_s > max_neg) inv_s = "0";
			}
		}
		else{
			for (string::reverse_iterator iter = s.rbegin(); iter != s.rend(); iter++){
				inv_s.push_back(*iter);
			}
			if (inv_s.length() > max_pos.length()) inv_s = "0";
			else if (inv_s.length() == max_pos.length()){
				if (inv_s > max_pos) inv_s = "0";
			}
		}
		return std::stoi(inv_s);
	}
};

int main(int argc, char** argv){
	//cout << ~0 << endl;
	cout << Solution().reverse(1000000003) << endl;
	//cout << std::stoi(std::to_string(s) << endl;
	// << stoi(to_string(numeric_limits<int>().min()));
	return 0;
}